from api.handler.ce.AbstractBatchCE import AbstractBatchCE
from api.model.BatchOutputPipe import BatchOutputPipe
from api.model.FdInputPipe import FdInputPipe
from munch import Munch
import json
# from config.annotation import Value

class DangerLevelHandler(AbstractBatchCE):
    """本科 研究生 博士生在校人数"""
    def do_compute(self, output_stream: BatchOutputPipe, source_fds: FdInputPipe, params: dict):
        bk_fd = source_fds.get_fd('VIEW_GJB_DATA_312')
        bk_sql = """
        SELECT max(ZXSSHJ) as undergraduate_num 
FROM `VIEW_GJB_DATA_312`
where ZYDM = 42100 and FILLUPYEAR = 2020
group by ZXSSHJ
        """
        bk_results = bk_fd.query(bk_sql)

        yjs_fd = source_fds.get_fd('VIEW_GJB_DATA_317')
        yjs_sql = """
        SELECT max(ZXSSHJ) as postgraduate_num 
FROM `VIEW_GJB_DATA_317`
where ZYDM = 43100 and FILLUPYEAR = 2020
group by ZXSSHJ
        """
        yjs_results = yjs_fd.query(yjs_sql)

        bss_fd = source_fds.get_fd('VIEW_GJB_DATA_318')
        bss_sql = """
        SELECT max(ZXSSHJ) as doctor_num 
FROM `VIEW_GJB_DATA_318`
where ZYDM = 43200 and FILLUPYEAR = 2020
group by ZXSSHJ
        """
        bss_results = bss_fd.query(bss_sql)

        data = Munch()
        data.undergraduate_num = bk_results[0].undergraduate_num
        data.postgraduate_num = yjs_results[0].postgraduate_num
        data.doctor_num = bss_results[0].doctor_num
        output_stream.output_for_upsert(data)



